package org.scboy.gateway;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.dubbo.config.annotation.DubboReference;
import org.scboy.dbms.api.AppManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

/**
 * 服务启动完成
 */
@Configuration
public class ServerStartReady implements ApplicationListener<ApplicationReadyEvent>{

	Log log=LogFactory.get();
	
	@Value("${spring.application.name}")
	private String appName="";

	@Value("${server.port}")
	int port;

	@DubboReference
	AppManager app;
	
	@Override
	public void onApplicationEvent(ApplicationReadyEvent event) {
		String ip="";
		try {
			InetAddress localHost=InetAddress.getLocalHost();
			ip=localHost.getHostAddress();
		} catch (UnknownHostException e) {
			log.error("无法获取服务器IP地址",e);
		}
		app.serverReady(ip, port, appName);
	}
}
